IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tr_ProjectFiles_Get]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[tr_ProjectFiles_Get]
GO

CREATE PROCEDURE [dbo].[tr_ProjectFiles_Get]
	@ProjectId UNIQUEIDENTIFIER
AS

SELECT
	tr_File.FileId,
	tr_Email.EntryDt,
	tr_Email.EmailAddress,
	tr_Email.Subject,
	tr_File.FileName,
	tr_File.MimeType,
	tr_File.FileData,
	tr_Email.Character,
	tr_Email.Description,
	tr_Email.Body,
	tr_File.EntryDt AS DateUploaded
FROM tr_email
	INNER JOIN tr_file ON (tr_File.EmailId = tr_Email.EmailId)
WHERE 
	ProjectId = @ProjectId
	and tr_File.DeletedInd = 0
	and tr_File.ArchivedInd = 0
